<template>
  <div>
    <el-form style="width: 500px;margin: auto;">
      <el-form-item label="下发人" label-width="100px">
        <el-input v-model="addzhu.createby" style="width: 250px;" disabled=""></el-input>
      </el-form-item>
      <el-form-item label="任务名称" label-width="100px">
        <el-input v-model="addzhu.rwname" style="width: 250px;"></el-input>
      </el-form-item>
      <el-form-item label="巡检线路" label-width="100px">
        <el-select v-model="addzhu.xid" style="width: 250px;" >
          <el-option v-for="item in xianlus" :label="item.xlnum" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="巡检员" label-width="100px">
      <el-select v-model="addzhu.users" multiple :multiple-limit="3" value-key="uid" style="width: 250px;">
        <el-option v-for="item in xunjianyuan" :label="item.uname" :value="item" :key="item.uid"></el-option>
      </el-select>
      </el-form-item>
      <template>
      <el-button @click="quxiao()">返 回</el-button>
      <el-button type="primary" @click="addclose()" >保 存</el-button>
      </template>
    </el-form>
</div>
</template>

<script>
  import axios from 'axios'
  export default{
    data(){
      return{
        addzhu:{
        id:'',
        rwid:'',
        createby:this.$store.state.user.uname,
        xid:'',
        runtype:0,
        oktime:'',
        type:'待分配',
        createtime:'',
        rwname:'',
        users:[],
        xunjianrenwuzis:[]
        },
        xianlus:[],
        xunjianyuan:[]
      }
    },
    methods:{
    addclose:function(){
    console.log('zhu',this.addzhu)
    if(this.addzhu.xid==null||this.addzhu.xid==''){
    this.$message('请选择巡检线路')
    return
    }
    if(this.addzhu.users==null||this.addzhu.users==''){
      this.$message('请选择巡检员')
      return
    }
    
    axios.post("http:localhost:8086/zhu/add",this.addzhu).then(vs=>{
      if(vs.status==200){
        this.$message("添加成功")
        this.$router.push({path:'/ZhiDingAndFenPei'})
      }else{
        this.$message("添加失败")
      }
    })
   
    },
    getXianlus:function(){
    axios.post('http:localhost:8086/xianlu/selectXianluByXunjian').then(vs=>{
      this.xianlus=vs.data
    })
    },
    quxiao:function(){
      this.$router.push({path:'/ZhiDingAndFenPei'})
    },
    getUsers:function(){
      axios.post("http:localhost:8086/user/selectRoleByxunjian").then(vs=>{
        this.xunjianyuan=vs.data
      })
    }
    },
    created() {
    this.getXianlus()
    this.getUsers()
    }
  }
</script>

<style>
</style>
